package com.ruoyi.bantong.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bantong.domain.BtUserBankcards;
import com.ruoyi.bantong.service.IBtUserBankcardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户银行卡Controller
 * 
 * @author laohei
 * @date 2021-02-04
 */
@RestController
@RequestMapping("/bantong/bankcards")
public class BtUserBankcardsController extends BaseController
{
    @Autowired
    private IBtUserBankcardsService btUserBankcardsService;

    /**
     * 查询用户银行卡列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtUserBankcards btUserBankcards)
    {
        btUserBankcards.setUserId(SecurityUtils.getBtUserId());
        startPage();
        List<BtUserBankcards> list = btUserBankcardsService.selectBtUserBankcardsList(btUserBankcards);
        return getDataTable(list);
    }

    /**
     * 导出用户银行卡列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:export')")
    @Log(title = "用户银行卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtUserBankcards btUserBankcards)
    {
        btUserBankcards.setUbId(SecurityUtils.getBtUserId());
        List<BtUserBankcards> list = btUserBankcardsService.selectBtUserBankcardsList(btUserBankcards);
        ExcelUtil<BtUserBankcards> util = new ExcelUtil<BtUserBankcards>(BtUserBankcards.class);
        return util.exportExcel(list, "bankcards");
    }

    /**
     * 获取用户银行卡详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:query')")
    @GetMapping(value = "/{ubId}")
    public AjaxResult getInfo(@PathVariable("ubId") Integer ubId)
    {
        return AjaxResult.success(btUserBankcardsService.selectBtUserBankcardsById(ubId));
    }

    /**
     * 新增用户银行卡
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:add')")
    @Log(title = "用户银行卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(BtUserBankcards btUserBankcards)
    {
        btUserBankcards.setUserId(SecurityUtils.getBtUserId());
        return toAjax(btUserBankcardsService.insertBtUserBankcards(btUserBankcards));
    }

    /**
     * 修改用户银行卡
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:edit')")
    @Log(title = "用户银行卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(BtUserBankcards btUserBankcards)
    {
        return toAjax(btUserBankcardsService.updateBtUserBankcards(btUserBankcards));
    }

    /**
     * 删除用户银行卡
     */
    //@PreAuthorize("@ss.hasPermi('bantong:bankcards:remove')")
    @Log(title = "用户银行卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ubIds}")
    public AjaxResult remove(@PathVariable Integer[] ubIds)
    {
        return toAjax(btUserBankcardsService.deleteBtUserBankcardsByIds(ubIds));
    }
}
